<?php
/**
 *
 * User: 无问西东
 * Date: 2023/3/3
 * Email: <121387209@qq.com>
 */

namespace addons\paotui\service;


use app\admin\model\paotui\Level;
use app\admin\model\paotui\UserLevel;

class User
{
    /**
     * 绑定默认等级
     */
    public static function bindDefaultLevel($user_id){

        //如果当前用户已经绑定过等级，返回
        $userLevelModel = new UserLevel();
        $userLevelInfo = $userLevelModel->where(['user_id'=>$user_id])->find();
        if(!empty($userLevelInfo)){
            return true;
        }
        //查看当前城市的默认等级
        $levelModel = new Level();
        $levelInfo = $levelModel->where(['is_default'=>1])->find();
        if(!empty($levelInfo)){
            $userLevelModel = new UserLevel();
            $userLevelModel->save(['user_id'=>$user_id,'level_id'=>$levelInfo['id']]);
        }
        return true;

    }
}